﻿package 
{
	//flash
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.utils.getDefinitionByName;
	import flash.text.TextField;
	//pureMVC
	//custom

	import com.tvein.System;
//
	public class preSystem extends MovieClip
	{
		private var _txtMsg:TextField = new TextField();
		public function preSystem()
		{
			addEventListener(Event.ENTER_FRAME, checkFrame);
			loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
			
			//show loader
			_txtMsg.textColor = 0x898989;
			_txtMsg.width = stage.stageWidth;
			_txtMsg.y = 120;
			_txtMsg.selectable = false;
			_txtMsg.autoSize = "center";
			_txtMsg.text = "Loading...";
			
			addChild(_txtMsg);
		}
		
		private function progress(evt:ProgressEvent):void
		{
			//update loader
			_txtMsg.text = "Loading..." + Math.floor(evt.bytesLoaded / evt.bytesTotal * 100) + "%";
		}
		
		private function checkFrame(evt:Event):void
		{
			if (currentFrame == totalFrames)
			{
				removeEventListener(Event.ENTER_FRAME, checkFrame);
				startup();
			}
		}
		
		private function startup():void
		{
			//hide loader
			removeChild(_txtMsg);
			
			stop();
			loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
			
			com.tvein.System;
			var mainClass:Class = getDefinitionByName("com.tvein.System") as Class;
			addChild(new mainClass() as DisplayObject);
		}
	}
}